package spring.cloud.tasks.executor.listener.failover;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import spring.cloud.tasks.executor.listener.election.ElectionNode;
import spring.cloud.tasks.executor.task.ExecuteNode;

/**
 * 失效转移节点名称的常量类.
 */
@Slf4j
@Setter
@Getter
public final class FailoverNode {

    static final String FAILOVER = "failover";

    static final String LEADER_ROOT = ElectionNode.ROOT + "/" + FAILOVER;

    static final String ITEMS_ROOT = LEADER_ROOT + "/items";

    static final String ITEM = ITEMS_ROOT + "/%s";

    static final String LATCH = LEADER_ROOT + "/latch";

    private static final String EXECUTION_FAILOVER = ExecuteNode.ROOT + "/%s/" + FAILOVER;

    private final String taskId;

    public FailoverNode(final String jobName) {
        this.taskId = jobName;
    }

    static String getItemsNode(final int item) {
        return String.format(ITEM, item);
    }

    public static String getExecutionFailoverNode(final int item) {
        return String.format(EXECUTION_FAILOVER, item);
    }

}
